/**
 * s_ldavg.c
 * Load average source for TrayInfo.
 * Load average support added by Laszlo Ashin <kodest@gmail.com>
 */

#include <stdio.h>

#include "trayinfo.h"

static int
ldavg_write(struct timeval *now, int fd)
{
	float ld[3];
	int i;
	FILE *f = fopen("/proc/loadavg", "r");
	if (!f) return 0;
	i = fscanf(f, "%f %f %f", ld, ld + 1, ld + 2);
	fclose(f);
	if (i != 3) return 0;

	printf("%.2f %.2f %.2f", ld[0], ld[1], ld[2]);
	return 1;
}

void
regsrc_ldavg(src_t *src)
{
	src->name = "ldavg";
	src->write = ldavg_write;
}
